/*
 * Copyright (c) 2021 Talkweb Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef IOT_ADC_H
#define IOT_ADC_H

typedef enum {
    /** Channel 0 */
    WIFI_IOT_ADC_CHANNEL_0,
    /** Channel 1 */
    WIFI_IOT_ADC_CHANNEL_1,
    /** Channel 2 */
    WIFI_IOT_ADC_CHANNEL_2,
    /** Channel 3 */
    WIFI_IOT_ADC_CHANNEL_3,
    /** Channel 4 */
    WIFI_IOT_ADC_CHANNEL_4,
    /** Channel 5 */
    WIFI_IOT_ADC_CHANNEL_5,
    /** Channel 6 */
    WIFI_IOT_ADC_CHANNEL_6,
    /** Channel 7 */
    WIFI_IOT_ADC_CHANNEL_7,
    /** Button value */
    WIFI_IOT_ADC_CHANNEL_BUTT,
} WifiIotAdcChannelIndex;

/**
 * @brief Enumerates analog power control modes.
 */
typedef enum {
    /** Automatic control */
    WIFI_IOT_ADC_CUR_BAIS_DEFAULT,
    /** Automatic control */
    WIFI_IOT_ADC_CUR_BAIS_AUTO,
    /** Manual control (AVDD = 1.8 V) */
    WIFI_IOT_ADC_CUR_BAIS_1P8V,
    /** Manual control (AVDD = 3.3 V) */
    WIFI_IOT_ADC_CUR_BAIS_3P3V,
    /** Button value */
    WIFI_IOT_ADC_CUR_BAIS_BUTT,
} WifiIotAdcCurBais;

/**
 * @brief Enumerates equation models.
 */
typedef enum {
    /** One-equation model */
    WIFI_IOT_ADC_EQU_MODEL_1,
    /** Two-equation model */
    WIFI_IOT_ADC_EQU_MODEL_2,
    /** Four-equation model */
    WIFI_IOT_ADC_EQU_MODEL_4,
    /** Eight-equation model */
    WIFI_IOT_ADC_EQU_MODEL_8,
    /** Button value */
    WIFI_IOT_ADC_EQU_MODEL_BUTT,
} WifiIotAdcEquModelSel;

unsigned int IoTAdcRead(WifiIotAdcChannelIndex channel, unsigned short *data, WifiIotAdcEquModelSel equ_model,
                     WifiIotAdcCurBais cur_bais, unsigned short delay_cnt);

float IOTAdcConvertToVoltage(unsigned short data);

#endif

